<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
?>
<script type="text/javascript" language="javascript">
    var allsiswaStoreSim = createStore(false, 'mallsiswaStoreSim',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_all');
    var combothajaranStoreSim = createStore(false, 'mcombothajaranStoreSim',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var piutangStoreGroup= createStoreGroup(false, 'mpiutangStoreGroup', [
        'id_piutang_siswa',
        'thbl', 
        'nis', 
        'nama', 
        'kd_kelas', 
        'kelas', 
        'id_th_ajaran', 
        'tahun_ajaran', 
        'semester', 
        'kd_biaya', 
        'biaya', 
        {name:'biaya_dikenakan', type:'float'},
        'detail_potongan',
        {name: 'total_potongan', type:'float'},
        {name:'total_biaya', type:'float'},
        {name:'pilih', type:'bool'},
        {name:'jumlah_bayar', type:'float'},
        {name:'pelunasan', type:'float'},
        {name:'saldo', type:'float'},
        'id_jenis', 
        'jenisbiaya', 
        'no_rek', 
        'fgroup'],
    'fgroup', '<?php echo base_url(); ?>' + 'simulasi/get_piutang');
    var simpotStore=createStoreGroup(false, 'simpotStore_id', 
    ['nis','kd_biaya','biaya',{name: 'potongan', type: 'float'},'keterangan','id_th_ajaran','thbl'],'biaya', 
    '<?php echo base_url(); ?>' + 'generatepiutang/get_rows_potongan_resgen');
    
    var rgroup='';
    var num = 0;
    //==========================================================================================
    var twinsiswasimStore = createStore(false, 'mtwinsiswasimStore',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_twin');
    defineTwinSiswa_windows('Windowfindsiswasim', 'Windowfindsiswasim_id', twinsiswasimStore, function(){			
        var sm = this.getSelectionModel();
        var sel = sm.getSelection();
        //                console.log('doublekil');
        if (sel.length > 0) {	
            Ext.getCmp('sim_nis').setValue(sel[0].get('nis'));
            Ext.getCmp('sim_nama').setValue(sel[0].get('nama'));
            Ext.getCmp('sim_kelas').setValue(sel[0].get('kelas'));  
            rgroup='';
            num = 0;
            var strsim=Ext.getCmp('gridsimulasi').getStore();
            var nis=sel[0].get('nis');
            var id_th_ajaran=Ext.getCmp('sim_id_th_ajaran').getValue();
            strsim.load({params:{nis:nis,id_th_ajaran:id_th_ajaran}});
            
            Ext.getCmp('Windowfindsiswasim_id').close();
            //            Ext.getCmp('biayasiswa_id_th_ajaran').focus();
        }
    });
    
    //===================
    Ext.define('Windowsimpot', {
        extend          : 'Ext.window.Window',
        title           : 'Form Detail Potongan',
        width           : 400,
        height          : 300,
        layout          : 'fit',
        autoShow        : true,
        modal           : true,
        alias           : 'widget.simpotEdit',
        id              : 'Windowsimpot_id',
        initComponent   : function(){
            this.items = [
                {xtype:'grid',
                    id:'gridsimpot',
                    stateful:true,
                    stateId:'stateGridsimpot',
                    store: simpotStore,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                    stripeRows: true,
                    loadMask: true   
                    ,
                    features: [{
                            id: 'group',
                            ftype: 'groupingsummary',
                            //            groupHeaderTpl: '{name}',
                            hideGroupedHeader: true,
                            enableGroupingMenu: false,
                            toggleSummaryRow:true
                        }]
                    ,columns:[
                        {
                            header: "Keterangan",
                            dataIndex: 'keterangan',
                            sortable: true,
                            width: 150     
                            ,align:'left'
                            //                                                ,hidden:true
                        },{
                            xtype:'numbercolumn',
                            header: "Potongan",
                            dataIndex: 'potongan',
                            sortable: true,
                            width: 100     
                            ,align:'right'
                            ,format:'0,0'
                            ,summaryType: 'sum'
                            ,summaryRenderer: function(value, summaryData, dataIndex) {
                                Ext.util.Format.thousandSeparator = ',';
                                Ext.util.Format.decimalSeparator = '.';
                                //                            metaData.tdCls='x-bls-header';
                                return Ext.util.Format.number(value,'0,000/i');
                            }
                        }
                    ]
                }
            ];
            this.callParent(arguments);
        }

    });
    //===================
    function validasiThbl(opt,store,thbl){
        var retval=true;
        if(opt==0){        
            store.each(function(node){
                if(parseInt(node.data.thbl)<parseInt(thbl)){                    
                    if(!node.data.pilih){
                        retval=false;                             
                    }
                }
            });            
        }
        if(opt==1){        
            store.each(function(node){
                if(node.data.thbl>thbl){
                    if(node.data.pilih){
                        node.data.pilih=false;
                        node.data.jumlah_bayar=0;
                        retval=false;   
                    }
                }
            });
        }
        return retval;
    }
    
    function CheckedPilih(opt,rowIndex,store,check){
        var gview=Ext.getCmp('gridsimulasi').getView();
        if(opt==0){        
            store.each(function(node){
                node.data.pilih=check;
                if(check){
                    node.data.jumlah_bayar=node.data.total_biaya;
                }else{
                    node.data.jumlah_bayar=0;
                }
                gview.refresh();
            });
        }
        if(opt==1){        
            store.each(function(node){
                if(node.data.thbl>thbl){
                    if(node.data.pilih){
                        return false;
                    }
                }
            });
        }
        return true;
    }
    function set_loadform(){
        Ext.getCmp('panelsimulasi').getForm().load({
            url: '<?= site_url("simulasi/get_form") ?>',
            failure: function(form, action){
                var de = Ext.util.JSON.decode(action.response.responseText);
                Ext.Msg.show({
                    title: 'Error',
                    msg: de.errMsg,
                    modal: true,
                    icon: Ext.Msg.ERROR,
                    buttons: Ext.Msg.OK,
                    fn: function(btn){
                        if (btn == 'ok' && de.errMsg == 'Session Expired') {
                            window.location = '<?= site_url("auth/login") ?>';
                        }
                    }
                });
            }
        });
    }
    //===================
    definWinPrint('WinPrintbayar', 'winprintbayar_id', 'widget.printbayar', 'Print Out Simulasi Pembayaran',
    'printoutbayar'
);
    
    setDefineWriter('Writer.paramprint',[
        {name:'nis',type:'string'},
        {name:'nama',type:'string'},
        {name:'kelas',type:'string'},
        {name:'thajaran',type:'string'},
        {name:'semester',type:'string'},
        {name:'keterangan',type:'string'},
        {name:'tglbayar',type:'string'}
    ]);
    
    function set_cetak(){
        var  paramsheader=new Writer.paramprint();
        var arrdata=new Array();
        var arrdetail=new Array();
        paramsheader.data=  
            {
            "nis":Ext.getCmp('sim_nis').getValue(),
            "nama":Ext.getCmp('sim_nama').getValue(),
            "kelas":Ext.getCmp('sim_kelas').getValue(),
            "thajaran":Ext.getCmp('sim_id_th_ajaran').getRawValue(),
            "semester":Ext.getCmp('sim_semester').getValue(),
            "keterangan":Ext.getCmp('sim_keterangan').getValue(),
            "tglbayar": Ext.Date.format(Ext.getCmp('sim_tglbayar').getValue(), 'd F Y')
        };
        arrdata.push(paramsheader.data);
        var store = Ext.getCmp('gridsimulasi').getStore();
        store.each(function(node){
            if(node.data.pilih && node.data.jumlah_bayar>0){
                arrdetail.push(node.data);
            }
                                
        });
        //                            console.log(arr);
        if(arrdetail.length==0)    {
                            
            //                                set_message(1, 'Data Pelunasan Tidak Valid / Belum Diisi');
            return;
        }
        var winprint=Ext.create('WinPrintbayar');
        winprint.show();
        to_print('printoutbayar', 'simulasi/cetak_bukti?data='+ Ext.JSON.encode(arrdata)+'&detail='+Ext.JSON.encode(arrdetail));
    }
    //===================
    defineTabFormDynamis(
    {
        name:'MyTabSimulasiPembayaran',
        xtype:'TabSimulasiPembayaran',
        alias:'widget.TabSimulasiPembayaran',
        title:'Simulasi Pembayaran',
        id:'tab12',
        items:[
            {
                xtype: 'form',
                autoShow: true,
                id: 'panelsimulasi',
                region: 'north',
                margins: '5 5 5 5',
                layout: 'column',                
                items:[
                    {
                        xtype: 'form',
                        columnWidth: .4,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 80,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype: 'twincombo'
                                ,name: 'nis'
                                ,fieldLabel: 'NIS',
                                tooltip: 'Field tidak boleh kosong',
                                afterLabelTextTpl: required_css,
                                id:'sim_nis',
                                store:twinsiswasimStore,
                                menu:'Windowfindsiswasim',
                                enableKeyEvents:true,
                                allowBlank:false
                                ,listeners:{
                                    keyup: function(f,e,opt) { 
                                        if (e.getKey()==113){
                                            f.onTrigger1Click();
                                        }          
                                        if (e.getKey()==13){
                                            if(f.getValue().length>0){
                                                var rec=  findNis(f.getValue(), allsiswaStoreSim);
                                                rgroup='';
                                                num = 0;
                                                if(rec){
                                      
                                                    Ext.getCmp('sim_nama').setValue(rec.get('nama'));
                                                    Ext.getCmp('sim_kelas').setValue(rec.get('kelas'));
                                                    var strsim=Ext.getCmp('gridsimulasi').getStore();
                                                    var nis=f.getValue();
                                                    var id_th_ajaran=Ext.getCmp('sim_id_th_ajaran').getValue();
                                                    
                                                    strsim.load({params:{nis:nis,id_th_ajaran:id_th_ajaran}});
                                                    //                                                    Ext.getCmp('sim_th_ajaran').focus();
                                                }else{
                                                    set_message(2,'Data Siswa Tidak Terdaftar !!!');
                                                    f.setValue('');
                                                }
                                            };
                                        }
                                    }
                                }
                                //                    ,readOnly:true                                    
                            }      
                            ,{
                                name: 'nama',
                                id: 'sim_nama',
                                fieldLabel: 'Nama Siswa',
                                maxLength:50,
                                emptyText: 'Nama Siswa',
                                allowBlank: true
                                ,readOnly:true                    
                            },{
                                name: 'kelas',
                                id: 'sim_kelas',
                                fieldLabel: 'Kelas',
                                maxLength:50,
                                emptyText: 'Kelas',
                                allowBlank: true
                                ,readOnly:true
                            },{
                                name: 'keterangan',
                                id: 'sim_keterangan',
                                fieldLabel: 'Keterangan',
                                maxLength:50,
                                emptyText: 'Keterangan',
                                allowBlank: false
                                ,tooltip: 'Field tidak boleh kosong',
                                afterLabelTextTpl: required_css
                                //                    ,readOnly:true                   
                            }
                        ]
                    },
                    //--------------------------------------------
                    {
                        xtype: 'form',
                        columnWidth: .4,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 100,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype: 'datefield',
                                name: 'tglbayar',
                                //                                        vtype:'daterange',
                                //                                        endDateField: 'jmon_tgl_akhir',
                                afterLabelTextTpl: required_css,
                                fieldLabel: 'Tanggal Bayar',
                                format:'d F Y',
                                value: new Date(),
                                anchor: '90%'
                                ,id:'sim_tglbayar'
                                ,readOnly:true
                            }     
                            ,{
                                xtype:'combo',
                                afterLabelTextTpl: required_css,
                                name: 'id_th_ajaran',
                                id: 'sim_id_th_ajaran',
                                fieldLabel: 'Tahun Ajaran',                                    
                                //                    labelWidth: 80,
                                emptyText: 'Tahun Ajaran'
                                ,mode:'local',
                                store: combothajaranStoreSim,
                                valueField: 'id_th_ajaran',
                                displayField: 'tahun_ajaran',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false  ,
                                hiddenName:'id_th_ajaran'
                                ,readOnly:true
                            },{
                                name: 'semester',
                                id: 'sim_semester',
                                fieldLabel: 'Semester',
                                maxLength:50,
                                emptyText: 'Semester',
                                afterLabelTextTpl: required_css,
                                readOnly:true
                            }
                        ]
                    }
                ]
            }
            ,{
                xtype: 'panel',
                autoShow: true,
                id: 'panelgridsimulasi',
                region: 'center',
                margins: '5 5 5 5',
                layout: 'fit',                
                items:[
                    {
                        xtype:'grid',
                        id:'gridsimulasi',
                        title:'',
                        stateful:true,
                        stateId:'stateGridsimulasi',
                        store: piutangStoreGroup,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                        stripeRows: true,
                        loadMask: true   
                        ,plugins: [
                            Ext.create('Ext.grid.plugin.CellEditing', {
                                clicksToEdit: 1
                            })
                        ]
                        ,selType: 'cellmodel'
                        //                        ,selType: 'checkboxmodel'
                        ,columnLines:true
                        ,columns:[
                            {xtype:'rownumberer'},
                            {
                                header: "THBL",
                                dataIndex: 'thbl',
                                sortable: true,
                                width: 50,                        
                                align:'center'
                                ,summaryType: function(records){
                                    return 'Total';
                                }
                                
                            },
                            {
                                header: "Jenis Pembayaran",
                                dataIndex: 'biaya',
                                sortable: true,
                                width: 150,                        
                                align:'left'
                                ,summaryType:'count'
                                ,summaryRenderer: function(value, summaryData, dataIndex) {
                                    return  '( ' + value +' jenis biaya )'
                                }
                                //                                ,summaryRenderer: function(value, summaryData, dataIndex) {
                                //                                    console.log(summaryData);
                                //                                    return 'Total';
                                //                                }
                            },{
                                xtype:'numbercolumn',
                                header: "Biaya Dikenakan",
                                dataIndex: 'biaya_dikenakan',
                                sortable: true,
                                width: 100     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'
                                ,summaryRenderer: function(value, summaryData, dataIndex) {
                                    Ext.util.Format.thousandSeparator = ',';
                                    Ext.util.Format.decimalSeparator = '.';
                                    return Ext.util.Format.number(value,'0,000/i');
                                }
                            },{
                                header: "Detail Potongan",
                                dataIndex: 'detail_potongan',
                                sortable: true,
                                width: 150                             
                            },{
                                xtype:'numbercolumn',
                                header: "Total Potongan",
                                dataIndex: 'total_potongan',
                                sortable: true,
                                width: 100     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'
                                //                        ,columnLines:true
                            },{
                                xtype:'numbercolumn',
                                header: "Total Biaya",
                                dataIndex: 'total_biaya',
                                sortable: true,
                                width: 80     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'                                
                                //                        ,columnLines:true
                            },{
                                xtype:'numbercolumn',
                                header: "Cicilan",
                                dataIndex: 'pelunasan',
                                sortable: true,
                                width: 80     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'
                                //                        ,columnLines:true
                            },{
                                xtype:'checkcolumn',
                                header:'Pilih',
                                dataIndex:'pilih',
                                sortable: false,
                                width: 50,
                                disabled:false,
                                listeners:{
                                    checkchange:function( cb, rowIndex, checked, eOpts ){
                                        if(checked){
                                            var selection= Ext.getCmp('gridsimulasi').getStore().getAt(rowIndex);
                                            //                                            var retval=validasiThbl(0,Ext.getCmp('gridsimulasi').getStore(),selection.get('thbl'));
                                            //                                            console.log(retval);
                                            if(!validasiThbl(0,Ext.getCmp('gridsimulasi').getStore(),selection.get('thbl'))){
                                                set_message(2, 'Tahun Bulan Sebelumnya Harus Dipilih!!');
                                                selection.set('pilih',false);
                                                Ext.getCmp('gridsimulasi').getView().refresh();
                                                return;
                                            }
                                            selection.set('jumlah_bayar',selection.get('saldo'));
                                            rgroup='';
                                            num = 0;
                                            Ext.getCmp('gridsimulasi').getView().refresh();
                                        }else{
                                            var selection= Ext.getCmp('gridsimulasi').getStore().getAt(rowIndex);
                                            selection.set('jumlah_bayar',0);                                            
                                            Ext.getCmp('gridsimulasi').getView().refresh();
                                            if(!validasiThbl(1,Ext.getCmp('gridsimulasi').getStore(),selection.get('thbl'))){
                                                //                                                set_message(2, 'Tahun Bulan Sebelumnya Harus Dipilih!!');
                                                //                                                selection.set('pilih',false);
                                                Ext.getCmp('gridsimulasi').getView().refresh();
                                                return;
                                            }
                                        }
                                    }
                                }
                            },{
                                xtype:'numbercolumn',
                                header: "Jumlah Bayar",
                                dataIndex: 'jumlah_bayar',
                                sortable: true,
                                width: 80     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'
                                ,field: {
                                    xtype: 'numberfield',
                                    hideTrigger: true,
                                    keyNavEnabled: false,
                                    mouseWheelEnabled: false,
                                    listeners:{
                                        change:function( f, newValue, oldValue, eOpts ){
                                            var selection=Ext.getCmp('gridsimulasi').getSelectionModel().getSelection();
                                            
                                            if(!selection[0].get('pilih')){
                                                set_message(2, 'Silahkan Centang Pilih Terlebih Dahulu!!!');
                                                f.setValue(0);   
                                                Ext.getCmp('gridsimulasi').getView().refresh();
                                                return;
                                            }
                                            if(selection[0].get('saldo')<newValue){
                                                set_message(2, 'Jumlah Bayar Lebih Besar Dari Total Biaya!!!');
                                                f.setValue(0);                                                
                                                Ext.getCmp('gridsimulasi').getView().refresh();
                                                return;
                                            }
                                            selection[0].set('jumlah_bayar',newValue);                                          
                                            Ext.getCmp('gridsimulasi').getView().refresh();

                                        }
                                        
                                    }
                                }
                                //                        ,columnLines:true
                            },{
                                xtype:'numbercolumn',
                                header: "Saldo",
                                dataIndex: 'saldo',
                                sortable: true,
                                width: 80     
                                ,align:'right'
                                ,format:'0,0'
                                ,summaryType: 'sum'
                                //                        ,columnLines:true
                            },{
                                xtype: 'actioncolumn',
                                width: 80,
                                sortable: false,
                                menuDisabled: true,
                                header: "View Potongan",
                                align:'center',
                                items: [{
                                        iconCls: 'icon-preview',
                                        tooltip: 'View Potongan',
                                        scope: this,
                                        handler: function(grid, rowIndex, colIndex){
                                            var selection= grid.getStore().getAt(rowIndex);
                                            //                                    kodeload=0;
                                            if (selection) {
                                                var thbl=selection.get('thbl');
                                                var nis =selection.get('nis');
                                                var kd_biaya=selection.get('kd_biaya');
                                                var winsimpot=Ext.create('Windowsimpot');
                                                //                                        var gridpot=Ext.getCmp('gridsimpot');
                                                   
                                                var store=Ext.getCmp('gridsimpot').getStore();
                                                store.load({params:{
                                                        thbl:thbl,
                                                        nis:nis,
                                                        kd_biaya:kd_biaya
                                                    }});

                                                //                                        winsimpot.setTitle('Add Form');                                                                        
                                                winsimpot.show();
                                    
                                                //                                            vGrid.getStore().remove(selection);                                            
                                            }
                                        
                                        }
                                    }]
                            }
                    
                        ]
                        ,
                        features: [{
                                id: 'group',
                                ftype: 'groupingsummary',
                                groupHeaderTpl: '{name}',
                                hideGroupedHeader: true,
                                enableGroupingMenu: false
                                ,collapsible:false
                                //                                ,summaryRowCls: 'h-summary'
                                ,showSummaryRow:false
                            }, {
                                ftype: 'summary',
                                dock: 'bottom'
                            }]
                        //                            ,viewConfig:[
                        //                                formBind:true
                        //                            ]
                    }
                ],
                tbar:[
                    '->',{
                        xtype: 'checkbox',
                        boxLabel:'Centang Untuk Pilih Semua',
                        id:'pilihsemua',
                        checked:false,
                        listeners:{
                            change:function( cb, newValue, oldValue, eOpts ){
                                var store=Ext.getCmp('gridsimulasi').getStore();
                                var gview=Ext.getCmp('gridsimulasi').getView();
                                if(newValue){
                                    if(store.getCount()>0){
                                        CheckedPilih(0, 0, Ext.getCmp('gridsimulasi').getStore(), newValue);
                                        gview.refresh();
                                    }else{
                                        cb.setValue(false);
                                    }
                                    
                                }else{
                                    CheckedPilih(0, 0, Ext.getCmp('gridsimulasi').getStore(), newValue);
                                    gview.refresh();
                                }
                            }
                        }
                    },{
                        xtype: 'button',
                        formBind: true,
                        text: 'Simpan Transaksi',
                        margins: '0 10 0 10',
                        iconCls: 'icon-simpan'
                        ,handler: function(){
                        
                            var parcmd='';
                            var thbl=null;
                            var thajaran='';
                            var arr=new Array();
                            var store=Ext.getCmp('gridsimulasi').getStore();
                            
                            store.each(function(node){
                                if(node.data.pilih && node.data.jumlah_bayar>0){
                                    arr.push(node.data);
                                }
                                
                            });
                            console.log(arr);
                            if(arr.length==0)    {
                            
                                set_message(1, 'Data Pelunasan Tidak Valid / Belum Diisi');
                                return;
                            }
                            var mtglbayar=Ext.Date.format(Ext.getCmp('sim_tglbayar').getValue(), 'Y-m-d')
                            
                            Ext.getCmp('panelsimulasi').getForm().submit({
                                clientValidation: true,
                                url: '<?php echo base_url(); ?>' + 'simulasi/proses_bayar',
                                scope: this,                               
                                params: {                                    
                                    mtglbayar:mtglbayar,
                                    postdata:Ext.JSON.encode(arr)
                                    
                                },
                                waitMsg: 'Mohon Tunggu Proses...',
                                //                    waitTitle:'Proses Pembuatan Piutang Thbl',
                                success: function(form, action) { 
                                    Ext.Msg.show({
                                        title:'Message Info',
                                        msg: action.result.msg,
                                        buttons: Ext.Msg.OK,
                                        icon: Ext.Msg.INFO,
                                        fn: function(btn){
                                            console.log(btn)
                                            if (btn == 'ok') {
                                                set_cetak();
                                                var strsim=Ext.getCmp('gridsimulasi').getStore();
                                                var nis=Ext.getCmp('sim_nis').getValue();
                                                var id_th_ajaran=Ext.getCmp('sim_id_th_ajaran').getValue();
                                                Ext.getCmp('panelsimulasi').getForm().reset();                                        
            //                                    strsim.load({params:{nis:nis,id_th_ajaran:id_th_ajaran}});
                                                strsim.load();
                                                set_loadform();
                                            }
                                        }
                                    });
                                    //                                     set_message(0,action.result.msg);
                                    //                    Ext.Msg.alert('Success', action.result.msg);
                                        
                                    
                                        
                                },
                                failure:function(form, action){
                                    switch (action.failureType) {
                                        case Ext.form.action.Action.CLIENT_INVALID:
                                            set_message(1, 'Masih Ada Data Yang Tidak Benar / Belum Diisi');
                                            break;
                                        case Ext.form.action.Action.CONNECT_FAILURE:
                                            set_message(1, 'Aplikasi Tidak Bisa Berkomunikasi dengan Server');
                                            break;
                                        case Ext.form.action.Action.SERVER_INVALID:
                                            set_message(1, action.result.msg);                                       
                                    }
                                    if(action.result.msg=='Session Expired') {
                                        session_expired(action.result.msg);
                                    }else{
                                        set_message(1, action.result.msg);
                                    }
                                }
                            });
                            
                        
                            
                        }
                    },{
                        xtype: 'button',
                        text: 'Cetak',
                        iconCls: 'icon-preview_report',
                        onClick: function(){
                            if(!Ext.getCmp('sim_nis').getValue()){
                                set_message(1, 'Masih Ada Data Yang Tidak Benar / Belum Diisi');
                                return;
                            }
                            var  paramsheader=new Writer.paramprint();
                            var arrdata=new Array();
                            var arrdetail=new Array();
                            paramsheader.data=  
                                {
                                "nis":Ext.getCmp('sim_nis').getValue(),
                                "nama":Ext.getCmp('sim_nama').getValue(),
                                "kelas":Ext.getCmp('sim_kelas').getValue(),
                                "thajaran":Ext.getCmp('sim_id_th_ajaran').getRawValue(),
                                "semester":Ext.getCmp('sim_semester').getValue(),
                                "keterangan":Ext.getCmp('sim_keterangan').getValue(),
                                "tglbayar": Ext.Date.format(Ext.getCmp('sim_tglbayar').getValue(), 'd F Y')
                            };
                            arrdata.push(paramsheader.data);
                            var store = Ext.getCmp('gridsimulasi').getStore();
                            store.each(function(node){
                                arrdetail.push(node.data);
                            })
                            var winprint=Ext.create('WinPrintbayar');
                            winprint.show();
                            to_print('printoutbayar', 'simulasi/cetak_bukti?data='+ Ext.JSON.encode(arrdata)+'&detail='+Ext.JSON.encode(arrdetail));
                        }
                    }
                ],
                bbar:[]
           
                    
                
            }
        ]
    },
    function(){
        //    Ext.getCmp('left_main').collapse();
    
//        Ext.Msg.show({
//                                        title:'Message Info',
//                                        msg: 'test',
//                                        buttons: Ext.Msg.OK,
//                                        icon: Ext.Msg.INFO,
//                                        fn: function(btn){
//                                            console.log(btn);                                            
//                                        }
//                                    });
        allsiswaStoreSim.load();
        combothajaranStoreSim.load();
        set_loadform();
        
    }        
);
        
        
</script>
